package com.chefu.carowner.controller;

import com.chefu.carowner.service.PositionService;
import com.chefu.common.constants.CfConstants;
import com.chefu.common.pojo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
public class PositionController {

    @Autowired
    private PositionService positionService;

    @PostMapping("/carOwner/location")
    public R saveLocation(@RequestBody Map<String,Object> map, HttpServletRequest request){
        String token = request.getHeader(CfConstants.APP_TOKEN_HEADER);
        Double latitude = (Double) map.get("latitude");
        Double longitude = (Double) map.get("longitude");
        String addrStr = (String) map.get("addrStr");
        positionService.saveLocation(request,latitude,longitude,addrStr);
        return R.ok();
    }

}
